package io.finer.erp.jeecg.jolimark.factory;

import io.finer.erp.jeecg.jolimark.comm.Config;
import io.finer.erp.jeecg.jolimark.enums.PrinterEnum;
import io.finer.erp.jeecg.jolimark.model.PrintRequestModel;
import io.finer.erp.jeecg.jolimark.print.CreateAccessToken;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Arrays;
import java.util.List;
import java.util.UUID;

/**
 * 打印机抽象工厂
 * 
 * @author Jolimark
 *
 */
public abstract class AbstractPrinterFactory {
	/**
	 * 打印机型号
	 */
	private PrinterEnum printerEnum;

	/**
	 * 设置打印机型号
	 * 
	 * @param printerEnum
	 */
	protected AbstractPrinterFactory(PrinterEnum printerEnum) {
		this.setPrinterEnum(printerEnum);
	}

	/**
	 * 创建请求参数
	 * 
	 * @return 打印机请求参数
	 */
	protected PrintRequestModel create() {
		PrintRequestModel model = new PrintRequestModel();
		model.setAccessToken( Config.getAccessToken());
		model.setAppId(Config.getAppID());
		model.setCusOrderId(UUID.randomUUID().toString().replaceAll("-", ""));
		model.setPaperWidth(printerEnum.getPaperWidth());
		model.setDeviceIds(createDeviceIds());
		return model;
	}

	private List<String> createDeviceIds() {
		String prtinerString = Config.getPrintDevice();
		return Arrays.asList(prtinerString.split(","));
	}

	public PrinterEnum getPrinterEnum() {
		return printerEnum;
	}

	private void setPrinterEnum(PrinterEnum printerEnum) {
		this.printerEnum = printerEnum;
	}
}
